/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"EE6067D6-E9DE-486B-B49F-6966576A1610",variableType:4}
 */
var zplan_ganancias_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"2AC1C053-099D-4874-AA73-64BE5559DE8B",variableType:4}
 */
var gAnioAsientos = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"424B664E-3497-477E-9949-CB57D7049834",variableType:4}
 */
var gMesAsientos = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"CAB4B3BB-BBBE-4439-97A1-C1256B28E1F1",variableType:8}
 */
var gtotal_asiento = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"1233E4B1-BB1E-46E2-A1DE-BB4D01689B7D",variableType:4}
 */
var gValorUnoAsientos = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C3FDE7DE-72E9-4F89-B721-486AB59A391B",variableType:4}
 */
var zplan_fletes_nac_terc_vent = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"1EFE5195-EAAB-4497-87AC-DBD3319ABE95",variableType:4}
 */
var zplan_fletes_int_terc_vent = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0447D5C3-FB15-4ADC-87FF-789935EED26F",variableType:4}
 */
var zplan_fletes_nac_prop_vent = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"B596402F-246E-4611-8C57-990AEBA418A0",variableType:4}
 */
var zplan_iva_debf = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"639D94FD-0560-42A4-BC57-8FC14364F202",variableType:4}
 */
var zplan_fletes_int_prop_vent = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4A8CFA72-1FE8-4F8A-B498-8E6EC3CB49D9",variableType:4}
 */
var zplan_fletes_internac = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3C2F4EBA-5D12-482E-B583-5AE6CE270852",variableType:4}
 */
var zplan_iva_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"BE455844-883C-447D-82E0-C4454DD9E651",variableType:4}
 */
var zplan_fletes_nacion = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4067CFDE-17D5-4C9D-99FE-3D8E81763A2D",variableType:4}
 */
var zplan_ing_brut_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"14FAA332-92EF-4562-87E9-62CB39072228",variableType:4}
 */
var zplan_itc = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FA683831-0F63-4D17-B782-E0C812CB62F3",variableType:4}
 */
var zplan_iva_cf = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"477CE30F-4438-4629-BD37-B64D64003AAA",variableType:4}
 */
var z_conf_asiento_apertura = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"99EDD023-8CD6-475F-8A6F-F45802B1071D",variableType:4}
 */
var z_conf_asiento_normal = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"2D4A313B-BD54-469C-A24C-4BF76DF907B9",variableType:4}
 */
var z_conf_asiento_cierre = 2;

/**
 * @param {String} [codigo]
 * 
 * @properties={typeid:24,uuid:"B1683C27-1B50-4ED5-BE76-9AC20DAE1D06"}
 */
function chequeaVariables(codigo)
{
	if (codigo == null)
		codigo = 'zplan_'
			
	var $globales = solutionModel.getGlobalVariables()
	
	var a2 = $globales.filter(function(item) { return item.name.indexOf(codigo, 0) != -1; });
	if (a2.length == 0)
		return [1,'Variables globales no encontradas']

	var msj = ''
	var res = 0
	for (var i = 0 ; i < a2.length ; i++)
	{
		if (globals[a2[i].name] == null || globals[a2[i].name] == 0)
		{
			msj += a2[i].name +'; '
			res = 1
		}
	}
	return [res,msj]
}

/**
 * @properties={typeid:24,uuid:"283D1972-8C71-4295-834D-32930DE535F9"}
 */
function crearFormErrores($form,$errores,$cols, $titulo)
{
	var $nombre = 'errores_asientos'
	forms[$form].elements.errores.removeAllTabs()
	var $frm 	= solutionModel.getForm($nombre)
	var tipos 	= new Array(JSColumn.TEXT,JSColumn.TEXT,JSColumn.TEXT)
	var dSource = $errores.createDataSource('ERRORES', tipos)
		
	if (!$frm)
	{
		
		history.removeForm($nombre)
		solutionModel.removeForm($nombre)
		
		var frm 		= solutionModel.newForm($nombre,dSource,null,null,false,880,60)
		frm.dataSource 	= dSource
		frm.view 		= JSForm.LOCKED_TABLE_VIEW
		frm.styleClass	= gusuario_to_rel_solucion_usuario.estilo
		frm.defaultPageFormat = '0;595.0;841.0;10.0;10.0;570.0;800.0'//'0; 595; 841; 0; 0; 545; 791'
	
		var $alt = frm.getBodyPart().height
		frm.newHeaderPart(40)
		var $lbl = frm.newLabel($titulo, 20, 10, 700, 20)
		$lbl.fontType 		= 'Tahoma,bold,12'
		$lbl.transparent 	= true
	
		$alt += frm.getHeaderPart().height
		frm.newFooterPart($alt + 20)
		var $met = frm.newMethod('function imprimir(){controller.showPrintPreview()}')
		var $btn = frm.newButton('Imprimir', 10, $alt + 1, 80, 20, $met)
		$btn.printable = false
		var $met_pdf = frm.newMethod('function PDF(){globals.crearPDF("errores")}')
		var $btn_pdf = frm.newButton('PDF', 100, $alt + 1, 80, 20, $met_pdf)
		$btn_pdf.printable = false
		
		
		var $fld = frm.newField($cols[0],JSField.TEXT_FIELD,0,frm.getBodyPart().getPartYOffset(),50,20)
		$fld.anchors 		= SM_ANCHOR.EAST | SM_ANCHOR.WEST
		$fld.titleText 		= $cols[0]
		$fld.borderType 	= 'LineBorder,1,#000000'
		$fld.fontType 		= 'Tahoma, plain, 8'
		$fld.editable		= false
		$fld.transparent 	= true
	
		$fld = frm.newField($cols[1],JSField.TEXT_FIELD,51,frm.getHeaderPart().height,340,20)
		$fld.anchors 		= SM_ANCHOR.EAST | SM_ANCHOR.WEST
		$fld.titleText 		= $cols[1]
		$fld.borderType 	= 'LineBorder,1,#000000'
		$fld.fontType 		= 'Tahoma, plain, 8'
		$fld.editable		= false
		$fld.transparent 	= true
			
		$fld = frm.newField($cols[2],JSField.TEXT_FIELD,392,frm.getHeaderPart().height,355,20)
		$fld.anchors 		= SM_ANCHOR.EAST | SM_ANCHOR.WEST
		$fld.titleText 		= $cols[2]
		$fld.borderType 	= 'LineBorder,1,#000000'
		$fld.fontType 		= 'Tahoma, plain, 8'
		$fld.editable		= false
		$fld.transparent 	= true
	}
	else
	{
		$frm.dataSource 	= dSource
	}
	forms[$nombre].controller.recreateUI()
	forms[$form].elements.errores.addTab(forms[$nombre])
}

/**
 * 
 * @param {Number} $tipo
 * @param {Number} $mes
 * @param {Number} $anio
 * 
 * @properties={typeid:24,uuid:"63B27E4D-36AC-4A5C-A102-D0E405B78647"}
 * @AllowToRunInFind
 */
function control_asientos_prov($tipo,$mes,$anio) 
{
	/** @type {JSFoundSet<db:/contable/asiento_prov_cab>}*/
	var $prov  = databaseManager.getFoundSet('contable','asiento_prov_cab')
	var $ok = $prov.find()
	if ($ok == false)
	{
		globals.DIALOGS.showWarningDialog('Aviso','Ocurrió un error al buscar asientos anteriores','OK')
		return 0
	}
	
	$prov.mes  				= $mes 
	$prov.anio 				= $anio
	$prov.tipo_asiento_id	= $tipo
	
	var $cant= $prov.search()
	if ($cant != 0) // Hay un corrida anterior
	{
		var $msj = 'Existe proceso anterior para este asiento en el rango de fechas solicitado. ¿Desea borrar lo anterior? '
		var resp = globals.DIALOGS.showQuestionDialog('Aviso', $msj,  "Si", "No" )
		if (resp == 'No')
			return 0
		else
		{  // borra los asientos encontrados (por la relacion borra los detalles)
			$ok = $prov.deleteAllRecords()
			if(!$ok)
			{
				globals.DIALOGS.showWarningDialog('Aviso','Ocurrió un error al borrar la corrida anterior','OK')  
				return 0   
			}
		}
	}
	return 1
}

/**
 * @properties={typeid:24,uuid:"EFE330B7-1A89-4AC9-850D-BFABEDE335DA"}
 */
function crearPDF($nombre) 
{
	globals.metodoPdf($nombre,'errores_'+ $nombre,true)
}
